/*
De network engine van snowmonky
*/
networkInit::networkInit(){
  nummerVanThreads = 0;
}
void networkInit::setupNetwork(){
  switch(type){
  case 1: {
    if(!setupServer())
      cout << "Kon geen socket aanvragen via default api\n";
    break;
  }
  case 0: {
    if(!setupClient())
      cout <<"Kon geen socket aanvragen wie default api\n";
    break;
  }
  }
}

bool networkInit::setupServer(){
  pthread_t mainLissingNetworkThread;

  socketDec = socket(AF_INET, SOCK_STREAM, 6);
  if(socketDec == -1)
    return false;
  //vul alles correct in voor de bind procedure
  struct sockaddr_in kin;
  bzero(&kin, sizeof(kin));
  kin.sin_family = AF_INET;
  kin.sin_addr.s_addr = INADDR_ANY;
  kin.sin_port = htons(port);
  if(-1 == bind(socketDec, (struct sockaddr *)&kin, sizeof(kin))){
    cout << "kan niet binden\n";
    return false;
  }
  
  //start de thread die gaat luisteren voor inkomende connecties
  #ifdef debug
  cout << "socketDec: " << socketDec << endl;
  #endif
  ThreadHandlers[nummerVanThreads] = pthread_create( &mainLissingNetworkThread, NULL, luister_voor_inkomende_connecties, (void *) socketDec);
  nummerVanThreads++;
}  

bool networkInit::setupClient(){
    cout << "Setup client\n";
    return true;
  }

  
